package com.ruoyi.app.controller;

import com.ruoyi.app.domain.AppUserExtend;
import com.ruoyi.app.service.IAppUserExtendService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户拓展Controller
 *
 * @author jiang
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/app/extend")
public class AppUserExtendController extends BaseController {
    @Autowired
    private IAppUserExtendService appUserExtendService;

    /**
     * 查询用户拓展列表
     */
    @PreAuthorize("@ss.hasPermi('app:extend:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppUserExtend appUserExtend) {
        startPage();
        List<AppUserExtend> list = appUserExtendService.selectAppUserExtendList(appUserExtend);
        return getDataTable(list);
    }

    /**
     * 导出用户拓展列表
     */
    @PreAuthorize("@ss.hasPermi('app:extend:export')")
    @Log(title = "用户拓展", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppUserExtend appUserExtend) {
        List<AppUserExtend> list = appUserExtendService.selectAppUserExtendList(appUserExtend);
        ExcelUtil<AppUserExtend> util = new ExcelUtil<AppUserExtend>(AppUserExtend.class);
        util.exportExcel(response, list, "用户拓展数据");
    }

    /**
     * 获取用户拓展详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:extend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appUserExtendService.selectAppUserExtendById(id));
    }

    /**
     * 新增用户拓展
     */
    @PreAuthorize("@ss.hasPermi('app:extend:add')")
    @Log(title = "用户拓展", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppUserExtend appUserExtend) {
        return toAjax(appUserExtendService.insertAppUserExtend(appUserExtend));
    }

    /**
     * 修改用户拓展
     */
    @PreAuthorize("@ss.hasPermi('app:extend:edit')")
    @Log(title = "用户拓展", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppUserExtend appUserExtend) {
        return toAjax(appUserExtendService.updateAppUserExtend(appUserExtend));
    }

    /**
     * 删除用户拓展
     */
    @PreAuthorize("@ss.hasPermi('app:extend:remove')")
    @Log(title = "用户拓展", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appUserExtendService.deleteAppUserExtendByIds(ids));
    }
}
